//
//  KDPatientInforViewController.m
//  LaiKeDaoClient
//
//  Created by dongkedi的iMac on 15/11/11.
//  Copyright © 2015年 LKD. All rights reserved.
//

#import "KDPatientInforViewController.h"
#import "KDMypatientTableViewCell.h"

@interface KDPatientInforViewController ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>{
    UITableView                 *_tableView;
    UILabel     *_label1,*_label2,*_label3,*_label4,*_label5,*_label6;
}


@end

@implementation KDPatientInforViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self setNaviTitle:@"患者个人信息"];
//    [self setNaviRightButton:@"编辑"];
    [self setNaviLeftButton];

    _tableView = [[UITableView alloc] initWithFrame:(CGRect){0,0,kScreenWidth,kScreenHeight-64} style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate   = self;
    _tableView.backgroundColor = [UIColor colorWithHexString:@"0xF2F2F2"];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.view addSubview:_tableView];
}

- (void)viewWillAppear:(BOOL)animated
{
    SharedAppDelegate.tabBarController.tabBarIsHiden = YES;
    if (self.dataDic.patient_code) {
        [self requestGetPatientDetailPatient_code:self.dataDic.patient_code info_type:@"all"];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    SharedAppDelegate.tabBarController.tabBarIsHiden = NO;
}

//
- (void)requestGetPatientDetailPatient_code:(NSString *)Patient_code info_type:(NSString *)info_type
{
    [CSHApiClient getPatientDetailPatient_code:Patient_code info_type:info_type DidFinishLoaded:^(KXJson *json, NSString *path) {
        //
        NSDictionary *dic1 = [NSDictionary dictionaryWithDictionary:[json getObjectForKey:@"data"]];
        [self reloadLabels:dic1];
    } didFailLoaded:^(NSError *error, NSString *path) {
        //
    }];
}

- (void)reloadLabels:(NSDictionary *)dic1
{
    if (dic1[@"clinic"]) {
        [_label1 setText:dic1[@"clinic"]];
    }
    if (dic1[@"ID_number"]) {
        [_label2 setText:dic1[@"ID_number"]];
    }
    if (dic1[@"birthday"]) {
        [_label3 setText:dic1[@"birthday"]];
    }
    if (dic1[@"height"]) {
        [_label4 setText:dic1[@"height"]];
    }
    if (dic1[@"weight"]) {
        [_label5 setText:dic1[@"weight"]];
    }
    if (dic1[@"weight_index"]) {
        [_label6 setText:dic1[@"weight_index"]];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
         return 1;
    }else{
         return 6;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 54;
    }else{
        return 44;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *CustomCellIdentifier = [NSString stringWithFormat:@"CellIdentifier%ld",(long)indexPath.row+indexPath.section*10];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];

    if (indexPath.section == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
        if (cell ==nil) {
            cell = [[KDMypatientTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier];
        }
    }else{
        cell = [tableView dequeueReusableCellWithIdentifier: CustomCellIdentifier];
        if (cell ==nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier];
            UIView  *line = [[UIView alloc] initWithFrame:(CGRect){10,43,kScreenWidth-20,1}];
            [line setBackgroundColor:[UIColor colorWithHexString:@"cccccc"]];
            [cell.contentView addSubview:line];
        }
        [cell.textLabel setFont:[UIFont systemFontOfSize:14]];
        switch (indexPath.row) {
            case 0:{
                cell.textLabel.text = @"门诊号";
                _label1 = [self createLabel];
                [cell.contentView addSubview:_label1];
            }break;
            case 1:{
                cell.textLabel.text = @"身份证号";
                _label2 = [self createLabel];
                [cell.contentView addSubview:_label2];
            } break;
            case 2:{
                cell.textLabel.text = @"出生日期";
                _label3 = [self createLabel];
                [cell.contentView addSubview:_label3];
            } break;
            case 3:{
                cell.textLabel.text = @"身高";
                _label4 = [self createLabel];
                [cell.contentView addSubview:_label4];
            }break;
            case 4:{
                cell.textLabel.text = @"体重";
                _label5 = [self createLabel];
                [cell.contentView addSubview:_label5];
            }break;
            case 5:{
                cell.textLabel.text = @"体重指数";
                _label6 = [self createLabel];
                [cell.contentView addSubview:_label6];
            }break;
            
            default:
                break;
        }
    }
    
    return cell;
}

- (UILabel *)createLabel
{
    UILabel *label = [[UILabel alloc] initWithFrame:(CGRect){kScreenWidth-200,0,175,44}];
    [label setTextAlignment:NSTextAlignmentRight];
    [label setFont:[UIFont systemFontOfSize:14]];
    [label setTextColor:[UIColor colorWithHexString:@"cccccc"]];
    return label;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
